﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.Entity;
using Jumpton.SFA.Server.BusinessRule;
using Jumpton.SFA.Server.BusinessRule.System;
using Jumpton.SFA.Server.BusinessRule.InStoreDataMeasures;
using Jumpton.Persistent;
using Jumpton.SFA.Entity;
public partial class Message_Look : PageBase
{
    #region 定义变量
  
    private MessageManager messManager = null;  //消息作类
    private Message message = null;              //消息对象
    private int messageID = -1;                  //消息ID号
   
    #endregion

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        int.TryParse(Request.QueryString["Mid"], out messageID);       
        if (!IsPostBack)
        {

            UpdateMessageReceiver();
            
             BindMessageLevel();
        }

        //获取消息ID号
      
        if (messageID > 0)
        {
            messManager = new MessageManager();
            message = messManager.LoadMessage(messageID);
            Fill(message);
           
        }
      
    }

    private void UpdateMessageReceiver(int messageID)
    {
        throw new NotImplementedException();
    }


    protected void BindMessageLevel()
    {
        DictionaryItemsManager dim = new DictionaryItemsManager();
        ddlMessageLevel.DataTextField = "Name";
        ddlMessageLevel.DataValueField = "DictionaryItemId";
        ddlMessageLevel.DataSource = dim.GetItemList(DictionaryEnum.MessageType, this.MyStateManager.DomainID);
        ddlMessageLevel.DataBind();
  
    }

    protected void Fill(Message mes)
    {
        txtTopic.Text = mes.TOPIC;
        txtStartTime.Text = Jumpton.SFA.Server.BusinessRule.BusinessLogic.GetDateTime(mes.BEGINDATE.ToString(), "yyyyMMdd", "yyyy-MM-dd");
             
        txtEndTime.Text = Jumpton.SFA.Server.BusinessRule.BusinessLogic.GetDateTime(mes.ENDDATE.ToString(), "yyyyMMdd", "yyyy-MM-dd");
          
        //chxActive.Checked = mes.ACTIVE;
        txtContent.Text = mes.CONTENT;
        ddlMessageLevel.SelectedValue = mes.CONTENTLEVEL.ToString();
        PHOTO p = null;
        try
        {
            p = new PhotoManager().Load(mes.PHOTOID);
        }
        catch { }
        
        if (p != null)
        {
            Image1.ImageUrl = "../UploadImages/" + p.PHOTOPATH;
            Image1.AlternateText = mes.TOPIC;
        }
        else
        {
            Image1.Visible = false;
        }
        
    }

    private void UpdateMessageReceiver()
    {
        messManager = new MessageManager();
         Message_Receive mr= messManager.LoadMessageReceive(messageID, MyStateManager.PersonID);
        if (mr!=null&&!mr.READFLAG)//更新状态为已读
         {
             mr.READFLAG = true;
             messManager.SaveMessage_Receive(mr);
         }
    }

   
}
